package eu.pago.chat.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.Registry;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JFrame;

import commonServer.IServer;

public class SignUpListener implements ActionListener {

	private final SignUpFrame frame;
	private final Registry registry;

	public SignUpListener(SignUpFrame frame, Registry registry) {
		this.frame = frame;
		this.registry = registry;
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		IServer serverCentral;
		List<InfoFriend> friends = new ArrayList<InfoFriend>();
		try {
			serverCentral = (IServer) registry.lookup("Server");
			serverCentral.addUser(frame.usernameTextField.getText(), "127.0.0.1");
		} catch (RemoteException | NotBoundException exc) {
			// TODO Auto-generated catch block
			exc.printStackTrace();
		}
		@SuppressWarnings("unused")
		JFrame friendsFrame = new FriendsFrame(friends);
		frame.dispose();
	}

}
